<template>
    <div id="app">
        <router-view/>
    </div>
</template>

<script>
import * as API from "./http/api.js";
export default {
  name: "App",
  created() {
    console.log(`test数据`, this.$store.state.test.test);
    this.$store.commit(`test/testFun`);
    this.setRouter();
    this.getUserInfo();
  },
  data() {
    return {
      userInfo: {
        isWho: ``, // z为专家 g为管理员 zg为专家和管理员 f没有权限
        option:[],
        data: {}
      }
    };
  },
  methods: {
    getUserInfo() {
      let that = this;
      console.log(that.userInfo.isWho);
      this.$http({
        method: "get",
        url: API.userInfo,
        params: {},
        customErr: true
      }).then(data => {
        console.log(`用户信息`, data);
        that.userInfo.data = data;
        if (data.expertId === null && data.isManager === false) {
          that.userInfo.isWho = "zg";
          that.userInfo.option = [
            { label: "管理员", value: 1 },
            { label: "专家", value: 2 }
          ];
          console.log(`既有管理员权限也有专家权限`, data);
          this.$store.commit("getInfoData", data);
        } else if (data.expertId != null && data.isManager === false) {
          that.userInfo.isWho = "z";
          data.option = [{ label: "专家", value: 2 }];
          console.log(`既有管理员权限也有专家权限`, data);
          this.$store.commit("getInfoData", data);
        } else if (data.expertId === null && data.isManager === true) {
          that.userInfo.isWho = "g";
          data.option = [{ label: "管理员", value: 2 }];
          console.log(`既有管理员权限也有专家权限`, data);
          this.$store.commit("getInfoData", data);
        } else {
          that.userInfo.isWho = "f";
          this.$store.commit("getInfoData", data);
        }
        window.localStorage.setItem(`userInfo`, JSON.stringify(that.userInfo));
        that.setRouter(that.userInfo.isWho);
      });
    },
    setRouter(type) {
      // 用户类型
      // 是否切换路由
      type=455
      console.log("专家");
      if (type === `z`) {
        this.navList = this.$store.state.router.typeA[0].children;
        this.$store.state.test.navList = this.navList;
        this.aaa = this.$store.state.router.typeA;
        this.$router.addRoutes(this.aaa);
        this.$router.push("/pages4");

        console.log("type === 0");
        // 管理员
      } else if (type === `g`) {
        this.navList = this.$store.state.router.typeB[0].children;
        this.$store.state.test.navList = this.navList;
        this.bbb = this.$store.state.router.typeB;
        this.$router.addRoutes(this.bbb);
        this.$router.push("/pages4");
        console.log("type === 1");
        // 专家和管理员
      } else if (type === `zg`) {
        this.navList = this.$store.state.router.typeC[0].children;
        this.$store.state.test.navList = this.navList;
        this.ccc = this.$store.state.router.typeC;
        this.$router.addRoutes(this.ccc);
        console.log("type === else");
      } else {
       this.$router.push('/404')
        console.log("type === else");
      }
    }
  }
};
</script>

<style>
</style>
